package cz.gelion.shylock.invoice.entity

import scala.beans.BeanProperty
import javax.persistence.Column
import javax.persistence.JoinColumn
import java.util.Set
import javax.persistence.ManyToOne
import javax.persistence.Entity
import javax.persistence.Table
import java.util.Calendar
import javax.persistence.Temporal
import javax.persistence.TemporalType
import javax.persistence.Id
import javax.persistence.GeneratedValue
import javax.persistence.OneToMany
import cz.gelion.shylock.invoice.ManagedInfo
import javax.persistence.PreUpdate
import javax.persistence.PrePersist
import javax.persistence.FetchType


@Entity
@Table(name="subject_unit")
class SubjectUnit extends ManagedInfo with Serializable {

  
	def this(s:Subject) = {
	  this
	  setSubject(s)
	}
  
	@Id
	@GeneratedValue
	@BeanProperty
	@Column(name="id")
	var id:Int = _
	
	@BeanProperty
	@ManyToOne
	@JoinColumn(name="subject")
	var subject:Subject = _

	@BeanProperty
	@Column(name="name")
	var name:String = _
   
	@BeanProperty
	@Column(name="note")
	var note:String = _
	
	@BeanProperty
	@ManyToOne
	@JoinColumn(name="muser")
	var manager:Manager = _
	
	
	@BeanProperty
	@Column(name="mtime")
	@Temporal(TemporalType.TIMESTAMP)
	var mtime:Calendar = _
	
	@BeanProperty
	@OneToMany(mappedBy="subjectUnit")
	var contacts:Set[Contact] = _
	
	@BeanProperty
	@OneToMany(mappedBy="id.subjectUnit", fetch=FetchType.EAGER)
	var accounts:Set[SubjectUnitAccount] = _
	
	
	@PreUpdate
	@PrePersist
	def preUpdate = {
	  stamp
	}
	
}